//
//  CustomViewOfCircle.m
//  TestDemo
//
//  Created by zhangwenqiao on 2018/12/18.
//  Copyright © 2018年 zhangwenqiao. All rights reserved.
//

#import "CustomViewOfCircle.h"

#define PI M_PI //圆周率常量
#define default_start_angle 0.0 //默认起始弧度
#define default_end_angle 2*PI //默认终点弧度
#define default_line_width 1.0 //默认线宽

@implementation CustomViewOfCircle

#pragma mark --------------->系统方法区<---------------
-(instancetype)init{
    self=[super init];
    if(self){
        
    }
    return self;
}

-(void)drawRect:(CGRect)rect{
    //圆心坐标点
    if (!isDefinedMyDot) {
        _myDot.x =self.frame.size.width/2;
        _myDot.y =self.frame.size.height/2;
    }
    
    //圆半径
    if (!isDefinedMyRadius) {
        _myRadius=(self.frame.size.width>self.frame.size.height)?self.frame.size.height/2:self.frame.size.width/2;
    }
    
    //弧度
    if (!isDefinedMyAngle) {
        _myAngle.x=default_start_angle;
        _myAngle.y=default_end_angle;
        
    }
    
    //线宽
    if (!isDefinedMyLineWidth) {
        _myLineWidth=default_line_width;
    }
    
    //方向
    if (!isDefinedMyClockWise) {
        _myClockWise=0;
    }
    
    
    CGContextRef context = UIGraphicsGetCurrentContext();
    //画弧线
    CGContextSetStrokeColorWithColor(context, _myStrokeColor.CGColor);
    CGContextSetLineWidth(context, _myLineWidth);//线的宽度
    CGContextAddArc(context, _myDot.x, _myDot.y, _myRadius, _myAngle.x, _myAngle.y, _myClockWise);
    CGContextDrawPath(context, kCGPathStroke); //绘制路径
}

#pragma mark --------------->自定义属性方法区<---------------

-(void)setMyCircleDot : (CGPoint) myCircleDot{
    _myDot.x=myCircleDot.x;
    _myDot.y=myCircleDot.y;
    isDefinedMyDot=YES;
}

-(void)setMyRadius:(CGFloat)myRadius{
    _myRadius=myRadius;
    isDefinedMyRadius=YES;
}

-(void)setMyAngle:(CGPoint)myAngle{
    _myAngle.x=myAngle.x;
    _myAngle.y=myAngle.y;
    isDefinedMyAngle=YES;
}

-(void)setMyLineWidth:(CGFloat)myLineWidth{
    _myLineWidth=myLineWidth;
    isDefinedMyLineWidth=YES;
}

-(void)setMyClockWise:(int)myClockWise{
    _myClockWise=myClockWise;
    isDefinedMyClockWise=YES;
}  

@end
